package cn.boot.asyncmy.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

/**
 * @author liangxin
 * @since 24/08/2019
 */
@Component
public class AsyncTask {
    @Async
    public AsyncResult<String> futrueTask1() throws InterruptedException {
        long t1 = System.currentTimeMillis();
        Thread.sleep(1000);
        long t2 = System.currentTimeMillis();
        System.out.println("--futrueTask1--->"+ (t2 - t1));
        return new AsyncResult<String>("futrueTask1执行完毕");
    }
    @Async
    public AsyncResult<String> futrueTask2() throws InterruptedException {
        long t1 = System.currentTimeMillis();
        Thread.sleep(1000);
        long t2 = System.currentTimeMillis();
        System.out.println("--futrueTask2--->"+ (t2 - t1));
        return new AsyncResult<String>("futrueTask2执行完毕");
    }
}
